package app.netant.finishbook.kenxing;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;

public class KenXingDetail extends BaseDetail {

	public KenXingDetail(String netSite) {
		super(netSite);
		this.preHref = "https://www.kenxingw.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".mainDiv.clearfix .leftDiv .box_7 .titleDiv h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements part2 = this.select(".mainDiv.clearfix .leftDiv .box_7 .titleDiv h2");
		if(part2.size()>0){
			String writers = part2.get(0).text();
			int idx = writers.indexOf("：");
			if(idx>0){
				writers = writers.substring(idx+1);
			}
			System.out.println("【Writer】:"+writers);
			this.entity.setNovelWriter(writers);
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".mainDiv.clearfix .leftDiv .box_7 .title_line_2 .headinfo .headinfo_left ul.ul li.infodiv ul.entry_info li span.item");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".mainDiv.clearfix .leftDiv .block .content_box_wrap .content_box .content_bd .box_2 .main #contents_more p");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		
		int st = this.netSite.lastIndexOf("/");
		int ed = this.netSite.lastIndexOf(".");
		
		if(st>0 && ed>st){
			String number = this.netSite.substring(st+1,ed);
			String href = "https://www.kenxingw.com/down.php?id="+number;
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
		
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".mainDiv #location_div a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		KenXingDetail detail = new KenXingDetail("https://www.kenxingw.com/xiaoshuo/xuanhuan/35811.html");
		detail.test();
	}



}
